<template>
  <view>
    <uni-popup ref="commendRef" type="bottom" :maskClick="false">
      <view class="popup-container">
        <scroll-view class="scroll-x" scroll-x="true" show-scrollbar="true"  scroll-y="true">
          <view class="table-container">
            <uni-table border stripe emptyText="暂无更多数据" class="data-table">
              <uni-tr>
                <uni-th width="100" align="center">仓库</uni-th>
                <uni-th width="80" align="center">仓位</uni-th>
                <uni-th width="100" align="center">批号</uni-th>
                <uni-th width="90" align="center">生产日期</uni-th>
                <uni-th width="150" align="center">件号</uni-th>
                <uni-th width="80" align="center">库存</uni-th>
                <uni-th width="70" align="center">操作</uni-th>
              </uni-tr>

              <uni-tr v-for="(item, index) in dataList" :key="index">
                <uni-td class="text-ellipsis">{{ item.stockName }}</uni-td>
                <uni-td class="text-ellipsis">{{ item.locationNo }}</uni-td>
                <uni-td class="text-ellipsis">{{ item.flot }}</uni-td>
                <uni-td class="text-ellipsis">{{ item.produceDate ? item.produceDate.substring(0,10) : '' }}</uni-td>
                <uni-td class="text-ellipsis">{{ item.fspecification }}</uni-td>
                <uni-td align="center" class="text-ellipsis">{{ item.FBASEQTY }}</uni-td>
                <uni-td align="center">
                  <button class="btn-return" @click="scanLocation(item)">返</button>
                </uni-td>
              </uni-tr>
            </uni-table>
          </view>
        </scroll-view>

        <view class="popup-footer" @click="closeInfoPop">
          <text>取消</text>
        </view>
      </view>
    </uni-popup>

    <add-pick ref="pickRef"></add-pick>
  </view>
</template>

<script>
import AddPick from "@/pages/pop/add-pick-commend.vue"
export default {
  components: { AddPick },
  data() {
    return {
      dataList: []
    }
  },
  methods: {
    scanLocation(item) {
      this.$emit('back', item)
      this.close()
    },
    closeInfoPop() {
      this.$refs.commendRef.close()
    },
    open(data) {
      this.dataList = data.dataList || []
      this.$refs.commendRef.open('center')
    },
    close() {
      this.$refs.commendRef.close()
    }
  }
}
</script>

<style lang="scss" scoped>
.popup-container {
  max-height: 90vh;
  background: #fff;
  display: flex;
  flex-direction: column;
  width: 90vw;
  margin: 0 auto;
  border-radius: 16rpx;
  overflow: hidden;
}

.scroll-x {
  width: 100%;
  max-height: 70vh;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.table-container {
  width: max-content;
  min-width: 100%;
  padding: 0;
}

/* ✅ 修改：调整表格最小宽度 */
.data-table {
  width: auto;
  min-width: 670px; /* 总宽度减少：100+80+100+90+150+80+70=670 */
  background: #fff;
  border-radius: 8rpx;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  table-layout: fixed;
}

/* ✅ 优化表头样式 */
:deep(.uni-th) {
  background-color: #f5f7fa !important;
  color: #333;
  font-weight: bold;
  font-size: 24rpx; /* 稍微减小字体 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 12rpx 8rpx; /* 调整内边距 */
}

/* ✅ 优化表格内容样式 */
:deep(.uni-td) {
  font-size: 24rpx; /* 稍微减小字体 */
  padding: 10rpx 6rpx; /* 调整内边距 */
  color: #444;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  line-height: 1.4;
}

/* ✅ 新增：文本省略号通用样式 */
.text-ellipsis {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* 按钮样式优化 */
.btn-return {
  background-color: #67c23a;
  color: #fff;
  border: none;
  border-radius: 6rpx;
  padding: 4rpx 12rpx;
  font-size: 22rpx; /* 按钮字体减小 */
  white-space: nowrap;
  min-width: 60rpx;
  height: 44rpx;
  line-height: 44rpx;
}

.popup-footer {
  height: 80rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f0f0;
  border-top: 1px solid #e5e5e5;
  font-size: 30rpx;
  color: #333;
  flex-shrink: 0;
}

.scroll-x::-webkit-scrollbar {
  height: 6px;
}

.scroll-x::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.scroll-x::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.scroll-x::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* ✅ 新增：移动端适配 */
@media (max-width: 768px) {
  .popup-container {
    width: 95vw;
  }
  
  .data-table {
    min-width: 670px;
  }
  
  :deep(.uni-th) {
    font-size: 22rpx;
    padding: 10rpx 6rpx;
  }
  
  :deep(.uni-td) {
    font-size: 22rpx;
    padding: 8rpx 4rpx;
  }
  
  .btn-return {
    padding: 2rpx 8rpx;
    font-size: 20rpx;
    min-width: 50rpx;
    height: 36rpx;
    line-height: 36rpx;
  }
}
</style>